package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 设备分组表(risk_device_group)迁移脚本
 */
public class A009_RiskDeviceGroupMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A009_RiskDeviceGroupMigrationScript() {
        super(
            "risk_device_group",
            "设备分组数据迁移",
            "ra_group",
            "risk_device_group",
            9
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_device_group (\n" +
               "  id,\n" +
               "  tenant_id,\n" +
               "  department_id,\n" +
               "  device_group_name,\n" +
               "  device_group_desc,\n" +
               "  sort_num,\n" +
               "  create_time,\n" +
               "  update_time,\n" +
               "  create_by,\n" +
               "  update_by,\n" +
               "  is_del\n" +
               ")\n" +
               "SELECT\n" +
               "  g.id,\n" +
               "  1 as tenant_id,\n" +
               "  g.tenant_id AS department_id,\n" +
               "  g.name,\n" +
               "  g.group_desc,\n" +
               "  g.sort_no,\n" +
               "  DATE_FORMAT(g.create_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "  DATE_FORMAT(g.update_time, '%Y-%m-%d %H:%i:%s'),\n" +
               "  1 AS create_by,\n" +
               "  1 AS update_by,\n" +
               "  g.is_del\n" +
               "FROM risk_lunnan_test.ra_group g\n" +
               "WHERE g.is_del = 0;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "  g.id,\n" +
               "  g.tenant_id,\n" +
               "  g.name,\n" +
               "  g.group_desc,\n" +
               "  g.sort_no,\n" +
               "  g.create_time,\n" +
               "  g.update_time,\n" +
               "  g.is_del\n" +
               "FROM risk_lunnan_test.ra_group g\n" +
               "WHERE g.is_del = 0;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_device_group (\n" +
               "  id,\n" +
               "  tenant_id,\n" +
               "  department_id,\n" +
               "  device_group_name,\n" +
               "  device_group_desc,\n" +
               "  sort_num,\n" +
               "  create_time,\n" +
               "  update_time,\n" +
               "  create_by,\n" +
               "  update_by,\n" +
               "  is_del\n" +
               ")";
    }
}
